CREATE SEQUENCE sq_actor
      INCREMENT 1
       MINVALUE 1
       MAXVALUE 2147483647
          START 1
          CACHE 1;
  
CREATE TABLE actor (actor_id INTEGER NOT NULL DEFAULT NEXTVAL('sq_actor')
                   ,first_name VARCHAR(45) NOT NULL
                   ,last_name VARCHAR(45) NOT NULL
                   ,last_update timestamp without time zone NOT NULL DEFAULT now()
                   ,CONSTRAINT pk_actor PRIMARY KEY (actor_id));

ALTER SEQUENCE sq_actor 
      OWNED BY actor.actor_id;

CREATE OR REPLACE FUNCTION last_updated()
RETURNS trigger 
AS
$BODY$
BEGIN
  NEW.last_update = CURRENT_TIMESTAMP;
  RETURN NEW;
END 
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;

CREATE TRIGGER last_updated 
 BEFORE UPDATE
            ON actor
  FOR EACH ROW EXECUTE PROCEDURE last_updated();

